<template>
  <view>
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
      <swiper-item v-for="item in swiperData" :key='item.goods_id'>
        <navigator class="swiper-item" :url="`/subpkg/goods_details/goods_details?goods_id=${item.goods_id}`">
          <image :src="item.image_src" mode=""></image>
        </navigator>
      </swiper-item>
    </swiper>
    <view class="nav-list">
      <view class="nav-item" v-for="(item,i) in navList" :key='i' @click="navClickHandler(item)">
        <image :src="item.image_src" mode=""></image>
      </view>
    </view>
    <view class="floor-list">
      <view class="floor-item" v-for="(item,i) in floorList" :key='i'>
        <image :src="item.floor_title.image_src" mode=""></image>
        <view class="floor-img-box">
          <navigator :url="item.product_list[0].url" class="left-img-box">
            <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
          </navigator>
          <view class="right-img-box">
            <navigator :url="item2.url" class="right-img-item" v-for="(item2,index) in item.product_list" :key='index' v-if="index!==0">
              <image :src="item2.image_src" mode="widthFix" :style="{width:item2.image_width+'rpx'}"></image>
            </navigator>
          </view>
         
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        swiperData: [],
        navList: [],
        floorList: []
      };
    },
    onLoad() {
      this.getSwiperData(),
        this.getNavList(),
        this.getFloorList()
    },
    methods: {
      async getSwiperData() {
        const {
          data: res
        } = await uni.$http.get('/home/swiperdata')
        console.log(res)
        if (res.meta.status !== 200) return uni.$showMsg()
        this.swiperData = res.message
      },
      async getNavList() {
        const {
          data: res
        } = await uni.$http.get('/home/catitems')
        console.log(res)
        if (res.meta.status !== 200) return uni.$showMsg()
        this.navList = res.message
      },
      navClickHandler(e) {
        console.log(e)
        if (e.name === "分类") {
          uni.switchTab({
            url: '../cate/cate'
          })
        }
      },
      async getFloorList() {
        const {
          data: res
        } = await uni.$http.get('/home/floordata')
        console.log(res)
        if (res.meta.status !== 200) return uni.$showMsg()
        res.message.forEach(floor=>{
          floor.product_list.forEach(prop=>{
            prop.url='/subpkg/goods_list/goods_list?' + prop.navigator_url.split('?')[1]
          })
        })
        this.floorList = res.message
      }
    }
  }
</script>

<style lang="scss">
  swiper {
    height: 330rpx;

    .swiper-item,
    image {
      width: 100%;
      height: 100%;
    }
  }

  .nav-list {
    display: flex;
    justify-content: space-around;
    margin: 32rpx 0;

    .nav-item image {
      width: 128rpx;
      height: 140rpx;
    }
  }

  .floor-list {
    .floor-item image {
      height: 60rpx;
      width: 100%;
    }
    .floor-img-box{
      display: flex;
      padding-left: 10rpx;
      .right-img-box{
        display: flex;
        flex-wrap: wrap;
        justify-content: space-around;
      }
    }
  }
</style>
